package
{
	import com.greensock.TweenMax;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;

	public class Tower extends Sprite
	{
		private var _srcImg		:BitmapData;
		private var _desImg		:BitmapData;
		private var _deltaTime	:Number = 0.0;
		private var _size		:Point;
		private var _maxSprite	:int = 0;
		private var _position	:Point;
		private var _index		:int = 0;
		
		public function Tower()
		{
			super();
		}
		
		public function init(bmd:BitmapData, size:Point, maxSprite:int, pos:Point):void
		{
			_position = pos;
			_maxSprite = maxSprite;
			_size = size;
			_srcImg = bmd;
			_desImg = new BitmapData(size.x, size.y);
			
			TweenMax.to(this, 0.1,{onComplete:startAnim});
		}
		
		public function startAnim():void
		{
			var srcRect:Rectangle = new Rectangle(0,_size.y * _index,_size.x,_size.y);
			_desImg.lock();
			_desImg.fillRect(srcRect,0xFFFFFF);
			_desImg.copyPixels(_srcImg, srcRect, new Point());
			_desImg.unlock();
			
			this.graphics.clear();
			this.graphics.beginBitmapFill(_desImg);
			this.graphics.drawRect(_position.x, _position.y, _size.x, _size.y);
			this.graphics.endFill();
			
			TweenMax.to(this, 0.1, {onComplete:startAnim});
		}
	}
}